package org.corey.share.auth;

import javax.servlet.ServletContext;

import org.corey.share.misc.Constants;

public class PermissionUtil {
	public static ServletContext sc;

	public static RoleAccessStrategory getAdminPermission() {
		if(sc==null){
			throw new IllegalStateException();
		}
		return (RoleAccessStrategory) (sc
				.getAttribute(Constants.ADMIN_PERMISSION_KEY));
	}

	public static void setAdminPermission(RoleAccessStrategory ras) {
		if(sc==null){
			throw new IllegalStateException();
		}
		sc.setAttribute(Constants.ADMIN_PERMISSION_KEY, ras);
	}

	public static void removeAdminPermission() {
		if(sc==null){
			throw new IllegalStateException();
		}
		sc.removeAttribute(Constants.ADMIN_PERMISSION_KEY);
	}

	public static void setServletContext(ServletContext sc) {
		PermissionUtil.sc = sc;
	}
}
